﻿/*
 * Author:杨进军
 * Feature:主框架JS
*/

var layout = {};

layout.init = function () {
    //用户悬停
    $("#btnUser").hover(function () {
        $(".user-list").show();
    }, function () {
        $(".user-list").hide();
    });
    //消息悬停
    $("#btnMsg").hover(function () {
        $(".msg-types").show();
    }, function () {
        $(".msg-types").hide();
    });
    //用户反馈弹框
    $(".userreply").bind("click", function () {
        art.dialog({
            id: "userReply",
            title: "用户反馈",
            lock: true,
            background: "#808080",
            opacity: 0.5,
            content: $("#userReply").html()
        });
    });
    //返回顶部
    var $backToTopEle = $(".gotop").click(function () {
        $("html, body").animate({ scrollTop: 0 }, 120);
    }), $backToTopFun = function () {
        var st = $(document).scrollTop(), winh = $(window).height();
        (st > 0) ? $backToTopEle.show() : $backToTopEle.hide();
        //IE6下的定位
        if (!window.XMLHttpRequest) {
            $backToTopEle.css("top", st + winh - 166);
        }
    };
    $(window).bind("scroll", $backToTopFun);
    $(function () {
        $backToTopFun();
    });
    //关闭系统消息
    $(".system-msgs-box .btn-close").click(function () {
        $(this).parent().remove();
    });

    $("#btnExit").bind("click", function () {
        var ishasodc = false;
        var isMySelf = false;
        $("#mainNav li").each(function () {
            if ($(this).text() == "报表中心") {
                ishasodc = true;
            }
            if ($(this).text() == "个人中心") {
                isMySelf = true;
            }
        });
        art.dialog({
            content: '<p class="tc">确认要退出三级市场业务管理系统吗？</p>',
            lock: true,
            title: '注销',
            ok: function () {
                $.AjaxAgency('/Account/SignOut', null, function (data) {
                    if (data.indexOf("ok,") > -1) {
                        //if (ishasodc == true) {
                        //    window.location.href = data.split(',')[2];
                        //}
                        if(isMySelf == true) {
                            window.location.href = data.split(',')[1];
                        }
                        else {
                            window.location = "/account/Login/";
                        }
                    } else {
                        $.OKDialogAgency('<div class="tc">退出失败！</div>');
                    }
                });
                return false;
            },
            cancelVal: '关闭',
            cancel: true //为true等价于function(){}
        });
    });
};

$(function () {
    $('<a href="javascript:;" class="gotop hide" title="快捷键T也可以返回顶部哦！"></a>').appendTo($("#gotop"));
    layout.init();
});
//快捷键翻页、返回顶部  yjj添加
window.pageConfig = window.pageConfig || {},
document.onkeyup = function(a) {
    var b = document.activeElement.tagName.toLowerCase();
    if ("input" != b && "textarea" != b) {
        var a = a ? a : window.event,
            c = a.keyCode || a.which;
        switch (c) {
        case 68:
            window.pageConfig.clientViewTop || (window.pageConfig.clientViewTop = 0),
            window.pageConfig.clientViewTop += document.documentElement.clientHeight,
            window.scrollTo(0, pageConfig.clientViewTop);
            break;
        case 84:
            window.scrollTo(0, 0),
            window.pageConfig.clientViewTop = 0
        }
    }
};

//验证
var VerifySendClick = function () {
    agencyVerify.notNullInput(".aui_content", ".aui_content #Content", true, "blur");
    $(".aui_content #Content").blur();

    if ($(".aui_content .wrong").length > 0) {
        return false;
    }
    else {
        return true;
    }
}

var userReply = function () {
    if (VerifySendClick()) {
        var reqData = {
            'ReceiverKeyId': "77777777-7777-7777-7777-777777777777",
            'Content': $('#Content').val()
        };
        $.AjaxAgency('/Center/batch-create-message', reqData, function (data) {
            if (data == 'ok') {
                $.OKDialogAgency('<div class="tc">发送成功！</div>', '提示', function () {
                    art.dialog.get("userReply").close();
                });
            } else {
                $.OKDialogAgency('<div class="tc">' + data + '</div>');
            }
        });
    }
}
